import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:hello_word/common/manager/provider_manager.dart';
import 'package:hello_word/common/manager/router_manager.dart';
import 'package:hello_word/l10n/localization_intl.dart';
import 'package:hello_word/models/locale_model.dart';
import 'package:hello_word/models/theme_model.dart';
import 'package:oktoast/oktoast.dart';
import 'package:provider/provider.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

void main() async {
  Provider.debugCheckInvalidValueType = null;

  runApp(App());
  // Android状态栏透明 splash为白色,所以调整状态栏文字为黑色
  SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
      statusBarBrightness: Brightness.dark,
      statusBarColor: Colors.transparent));
  // iOS
}

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return OKToast(
      child: MultiProvider(
        providers: providers,
        child: Consumer2<ThemeModel, LocaleModel>(
            builder: (context, themeModel, localeModel, child) {
          return RefreshConfiguration(
              hideFooterWhenNotFull: true,
              child: MaterialApp(
                debugShowCheckedModeBanner: false,
                localizationsDelegates: const [
                  MyLocalizations.delegate,
                  GlobalCupertinoLocalizations.delegate,
                  GlobalWidgetsLocalizations.delegate,
                  GlobalMaterialLocalizations.delegate,
                ],
                supportedLocales: MyLocalizations.delegate.supportedLocales,
                theme: ThemeData(
                  backgroundColor: Colors.black,
                  primaryColor: Colors.brown,
                ),
                onGenerateRoute: Router.generateRoute,
                initialRoute: RouteName.splash,
                color: Colors.green,
              ));
        }),
      ),
    );
  }
}
